package com.zlsy.springbootdemo.chainofresponsibility.mtdemo2.config;

import com.zlsy.springbootdemo.chainofresponsibility.mtdemo2.Rule;
import com.zlsy.springbootdemo.chainofresponsibility.mtdemo2.rule.CityInfoRule;
import com.zlsy.springbootdemo.chainofresponsibility.mtdemo2.rule.ServiceAvailableRule;
import com.zlsy.springbootdemo.chainofresponsibility.mtdemo2.rule.UserGroupRule;
import com.zlsy.springbootdemo.chainofresponsibility.mtdemo2.rule.UserPortraitRule;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.LinkedList;
import java.util.List;

/**
 * @author zhouliang
 * @date 2021/1/23 16:10
 */
@Slf4j
@Configuration
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class BeanConfig {
  private final ServiceAvailableRule serviceAvailableRule;
  private final UserGroupRule userGroupRule;
  private final CityInfoRule cityInfoRule;
  private final UserPortraitRule userPortraitRule;

  @Bean(name = "userPortraitRules")
  public List<Rule> initRuleChain() {
    LinkedList<Rule> rules = new LinkedList<>();
    rules.add(serviceAvailableRule);
    rules.add(userGroupRule);
    rules.add(cityInfoRule);
    rules.add(userPortraitRule);
    log.info("userPortraitRuleChain init success！");
    return rules;
  }
}
